/**
 * Created by 余保林 on 2017/9/27.
 */
module.exports = {
  listAction () {
    this.allowMethods = 'get'
    let rules = {
      page: {
        required: true,
        int: { min: 1 },
        method: 'GET',
        aliasName: '页数'
      },
      pageSize: {
        required: true,
        int: { min: 1 },
        method: 'GET',
        aliasName: '每页大小'
      },
      field: {
        requiredWithAll: ['value'],
        method: 'GET',
        aliasName: '搜索字段'
      },
      value: {
        method: 'GET',
        aliasName: '搜索值'
      }
    }
    let messages = {
      required: '{name}不能为空',
      int: '{name}必须为大于1的整数',
      requiredWith: '{name}不能为空'
    }
    this.validate(rules, messages)
  },
  __after () {
    if (!think.isEmpty(this.validateErrors)) {
      let errorMSg = []
      for(let field in this.validateErrors) {
        errorMSg.push(this.validateErrors[field])
      }
      return this.fail(errorMSg.join('<br/>'), this.validateErrors)
    }
  }
}